package com.qiche.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qiche.service.ResourcesService;
import com.qiche.mapper.ResourcesMapper;
import com.qiche.model.Resources;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * Created by Linzw on 2018/01/24.
 */
@Service("resourcesService")
public class ResourcesServiceImpl extends BaseService<Resources> implements ResourcesService {
	@Resource
	private ResourcesMapper resourcesMapper;

	@Override
	public PageInfo<Resources> selectByPage(Resources resources, int page, int limit) {
		// int page = start/length+1;
		Example example = new Example(Resources.class);
		// 分页查询
		PageHelper.startPage(page, limit);
		List<Resources> userList = selectByExample(example);
		return new PageInfo<>(userList);

	}

	@Override
	public List<Resources> selectByParentId(Integer parentId) {
		Example example = new Example(Resources.class);
		// 分页查询
		Example.Criteria criteria=example.createCriteria();
		criteria.andEqualTo("parentid",parentId);
		List<Resources> userList = selectByExample(example);
		return userList;

	}

	@Override
	public List<Resources> queryAll() {
		return resourcesMapper.queryAll();
	}

	// @Cacheable(cacheNames="resources",key="#map['userid'].toString()+#map['type']")
	@Override
	public List<Resources> loadUserResources(Map<String, Object> map) {
		return resourcesMapper.loadUserResources(map);
	}

	@Override
	public List<Resources> queryResourcesListWithSelected(Integer rid,Integer prid) {
		return resourcesMapper.queryResourcesListWithSelected(rid,prid);
	}

	@Override
	public List<Resources> queryTopResourcesListWithSelected(Integer rid) {
		return resourcesMapper.queryTopResourcesListWithSelected(rid);
	}
}
